-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(api-service): implement multi subscription with condition to topic fixes NV-6810 #9370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
feat(api-service): implement multi subscription with condition to topic fixes NV-6810 #9370
Conversation
…ions - Introduced resourceConditions and subscriberConditions in the topic subscriptions feature to allow conditional notifications based on JSONLogic rules. - Added a new EvaluateSubscriptionConditions use case to evaluate these conditions. - Updated relevant DTOs and repositories to support the new fields and logic. - Included a condition hash for efficient subscription management. - Added json-logic-js as a dependency for condition evaluation.
❌ Deploy Preview for dashboard-v2-novu-staging failed. Why did it fail? →
|
…te repository methods - Renamed 'condition' to 'conditions' across various DTOs and use cases for consistency. - Updated the TopicSubscribersRepository to implement a new method for bulk subscription creation, returning detailed results for created, updated, and failed subscriptions. - Removed the EvaluateSubscriptionConditions use case as its functionality has been integrated into the TriggerMulticast use case. - Adjusted related logic to accommodate the new structure for conditions.
1 Job Failed: Check pull request / Find LaunchDarkly feature flags in diff failed on "Find flags"
Summary: 3 successful workflows, 1 failed workflow
Last updated: 2025-10-20 17:58:34 UTC |
if (conditionHash !== undefined) { | ||
existingSubscriptionsQuery.conditionHash = conditionHash; | ||
} else { | ||
existingSubscriptionsQuery.$or = [{ conditionHash: { $exists: false } }, { conditionHash: null }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate if we ca use rooted $or
const passingSubscriptions = subscriptionsBatch.filter((subscription) => { | ||
return this.evaluateConditions( | ||
subscription.conditions as Record<string, unknown>, | ||
{ payload: command.payload } as Record<string, unknown> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we will need to add workflow entity variable as well
const cursor = this._model | ||
.find( | ||
{ | ||
_organizationId: this.convertStringToObjectId(_organizationId), | ||
_environmentId: this.convertStringToObjectId(_environmentId), | ||
_topicId: { $in: mappedTopicIds }, | ||
externalSubscriberId: { $nin: excludeSubscribers }, | ||
}, | ||
}, | ||
{ | ||
$group: { | ||
_id: '$externalSubscriberId', | ||
topics: { $push: '$_topicId' }, | ||
}, | ||
}, | ||
]; | ||
{ | ||
externalSubscriberId: 1, | ||
conditions: 1, | ||
} | ||
) | ||
.cursor({ batchSize }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the missing grouping by subscriber id could couse more copute, because we could fetch duplicated subscribers, however we still need them because 1 subscriber could pass the condition while the other will not.
- Enhanced the topic subscriptions feature by introducing a new workflows field in the relevant DTOs and use cases. - Updated the TopicsController to handle workflows in subscription requests. - Modified the CreateTopicSubscriptions use case to process and store workflows associated with subscriptions. - Added validation and transformation logic for workflows in the DTOs. - Updated end-to-end tests to verify the correct handling of workflows in subscription creation.
What changed? Why was the change needed?
Screenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer